jQuery.noConflict();

UWA.Class = Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.apply(object, [event || window.event]);
  }
}

document.getElementsByClassName = function(className) {
  return jQuery("." + className)
}

UWA.Ajax = {
  Request: function(url, request) {
    if(request.parameters) request.data = request.parameters;
    if(request.postBody) request.data = request.postBody;
    jQuery.ajax( { type: request.method, url: url, success: request.onComplete, data: request.data } )
  },
  onCompleteXML: function(arg, callback, context) {
    callback(arg[0]);
  },
  onCompleteText: function(arg, callback, context) {
    callback(arg[0]);
  },
  onCompleteJson: function(arg, callback, context) {
    try {
      eval("var j = " + arg[0]);
      callback(j, context);
    } catch(e) {
      UWA.log(e);
    }
  }
}

UWA.Form = {
  getElements: function(form) {
    return jQuery(':input', form)
  }
}

$ = UWA.$element = function(el){
  if (el) {
    if (!el.isUwaExtended) {
      UWA.extend(el, UWA.Element);
      el.isUwaExtended = true;
    } 
    return jQuery(el)[0];
  }
}

if (typeof UWA.Element == "undefined") UWA.Element = {};

// if (typeof UWA.Element.methods == "undefined") UWA.Element.methods = {};

UWA.extend(UWA.Element, {
  
  hide: function() {
   return this.setStyle('display', 'none');
  },
  show: function() {
    return this.setStyle('display', '');
  },
  toggle: function() {
    if(this.style.display == 'none') {
      this.style.display = '';
    } else {
      this.style.display = 'none';
    }
  },
  remove: function() {
    return this.parentNode.removeChild(this);
  },
  setStyle: function(arg1, arg2) {
    if (typeof arg1 == 'string' && typeof arg2 != 'undefined') { // key->value syntax
      return jQuery(this).css(arg1, arg2);
    } else { // object syntax
      return jQuery(this).css(arg1);
    }
  },
  getDimensions: function() {
    return { 'width' : jQuery(this).width(), 'height' : jQuery(this).height() }
  },
  hasClassName: function(className) {
   return jQuery.className.has(this, className);
  },
  addClassName: function(className) {
    return jQuery.className.add(this, className);
  },
  removeClassName: function(className) {
    return jQuery.className.remove(this, className);
  },
  getElementsByClassName: function(className) {
    return jQuery("." + className, this)
  }
});

// Compatibility with prototype style (TabView)

if (typeof Element == "undefined") var Element = {};

Element.addClassName = function(el, className) {
  return jQuery.className.add(el, className);
}
Element.removeClassName = function(el, className) {
  return jQuery.className.remove(el, className);
}
Element.show = function(el) {
  return el.style.display == '';
}
Element.hide = function(el) {
  return el.style.display == 'none';
}